# Maintainer: Wolfgang Stöggl <c72578@yahoo.de>

_realname=sox
_base_ver=14.4.2
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
# https://sourceforge.net/p/sox/code/ci/07de8a77a862e6800b95a8d3a61c6b4e41362755/
pkgver=14.4.2.r3203.07de8a77
pkgrel=2
pkgdesc="SoX is the Swiss Army Knife of sound processing utilities (mingw-w64)"
arch=('any')
url="https://sourceforge.net/projects/sox/"
license=("GPL")
makedepends=(autoconf-archive git
             ${MINGW_PACKAGE_PREFIX}-flac
             ${MINGW_PACKAGE_PREFIX}-gcc
             ${MINGW_PACKAGE_PREFIX}-gsm
             ${MINGW_PACKAGE_PREFIX}-id3lib
             ${MINGW_PACKAGE_PREFIX}-lame
             ${MINGW_PACKAGE_PREFIX}-libao
             ${MINGW_PACKAGE_PREFIX}-libid3tag
             ${MINGW_PACKAGE_PREFIX}-libmad
             ${MINGW_PACKAGE_PREFIX}-libpng
             ${MINGW_PACKAGE_PREFIX}-libsndfile
             ${MINGW_PACKAGE_PREFIX}-libtool
             ${MINGW_PACKAGE_PREFIX}-libvorbis
             ${MINGW_PACKAGE_PREFIX}-opencore-amr
             ${MINGW_PACKAGE_PREFIX}-opusfile
             ${MINGW_PACKAGE_PREFIX}-pkg-config
             ${MINGW_PACKAGE_PREFIX}-twolame
             ${MINGW_PACKAGE_PREFIX}-vo-amrwbenc
             ${MINGW_PACKAGE_PREFIX}-wavpack)
depends=(${MINGW_PACKAGE_PREFIX}-gcc-libs
             ${MINGW_PACKAGE_PREFIX}-flac
             ${MINGW_PACKAGE_PREFIX}-gsm
             ${MINGW_PACKAGE_PREFIX}-id3lib
             ${MINGW_PACKAGE_PREFIX}-lame
             ${MINGW_PACKAGE_PREFIX}-libao
             ${MINGW_PACKAGE_PREFIX}-libid3tag
             ${MINGW_PACKAGE_PREFIX}-libmad
             ${MINGW_PACKAGE_PREFIX}-libpng
             ${MINGW_PACKAGE_PREFIX}-libsndfile
             ${MINGW_PACKAGE_PREFIX}-libtool
             ${MINGW_PACKAGE_PREFIX}-libvorbis
             ${MINGW_PACKAGE_PREFIX}-opencore-amr
             ${MINGW_PACKAGE_PREFIX}-opusfile
             ${MINGW_PACKAGE_PREFIX}-twolame
             ${MINGW_PACKAGE_PREFIX}-vo-amrwbenc
             ${MINGW_PACKAGE_PREFIX}-wavpack)
options=('staticlibs' 'strip')
source=("${_realname}"::"git+https://git.code.sf.net/p/sox/code#commit=07de8a77a862e6800b95a8d3a61c6b4e41362755")
sha256sums=('SKIP')

pkgver() {
  cd "${srcdir}/${_realname}"
  printf "%s.r%s.%s" "${_base_ver}" "$(git rev-list --count HEAD)" "$(git rev-parse --short HEAD)"
}

prepare() {
  cd "${srcdir}/${_realname}"
  autoreconf -i
}

build() {
  mkdir -p "$srcdir/build-${MINGW_CHOST}" && cd "$srcdir/build-${MINGW_CHOST}"
  ../${_realname}/configure \
    --prefix=${MINGW_PREFIX} \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --with-distro='MSYS2 MINGW-packages'

  make CFLAGS="$CFLAGS -D__USE_MINGW_ANSI_STDIO=1"
}

package() {
  cd "${srcdir}/build-${MINGW_CHOST}"
  make DESTDIR="${pkgdir}" install
  make DESTDIR="${pkgdir}" installcheck
}
